package com.mall.shopping.services;

import com.mall.shopping.IContentService;
import com.mall.shopping.constants.ShoppingRetCode;
import com.mall.shopping.converter.ContentConverter;
import com.mall.shopping.dal.entitys.PanelContent;
import com.mall.shopping.dal.entitys.PanelContentItem;
import com.mall.shopping.dal.persistence.PanelContentMapper;
import com.mall.shopping.dto.NavListResponse;
import com.mall.shopping.dto.PanelContentDto;
import org.apache.dubbo.config.annotation.Service;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;

@Service
public class INavigationServiceImpl implements IContentService {

    @Autowired
    PanelContentMapper panelContentMapper;
    @Autowired
    ContentConverter contentConverter;
    @Override
    public NavListResponse queryNavList() {
        NavListResponse navListResponse = new NavListResponse();
        ArrayList<PanelContentDto> panelContentDtoArrayList = new ArrayList<>();
        try {
            List<PanelContentItem> panelContentItemList = panelContentMapper.selectPanelContentAndProductWithPanelId(0);
            for (PanelContentItem panelContentItem : panelContentItemList) {
                PanelContentDto panelContentDto = contentConverter.panelContentItem2Dto(panelContentItem);
                panelContentDtoArrayList.add(panelContentDto);
            }
            navListResponse.setCode(ShoppingRetCode.SUCCESS.getCode());
            navListResponse.setMsg(ShoppingRetCode.SUCCESS.getMessage());
            navListResponse.setPannelContentDtos(panelContentDtoArrayList);
        } catch (Exception e) {
            e.printStackTrace();
            navListResponse.setCode(ShoppingRetCode.DB_EXCEPTION.getCode());
            navListResponse.setMsg(ShoppingRetCode.DB_EXCEPTION.getMessage());
        }
        return navListResponse;
    }

}
